﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.UI.HtmlControls;

using Sketchial.Business;

namespace Skecthial.UI.Controls
{
    public partial class Posts : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("PostContent");
            dt.Columns.Add("User");
            dt.Columns.Add("userImage");
            dt.Columns.Add("userid");
            dt.Columns.Add("userfullname");
            dt.Columns.Add("where");
            dt.Columns.Add("when");
            dt.Columns.Add("what");

            for (int i = 0; i < 2; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = "sbaytar" + " has created a new event wtih following people";
                dr[0] = "WITH;";
                dr[1] = "<a class='personPopupTrigger' rel='rel' type='people' name='" + "Boss.png" + "' href='#'><img src='../assets/images/profile.jpg' width='40' height='40' /></a>";
                dr[2] = "../assets/images/profile.jpg";
                dr[3] = "1111";
                dr[4] = "2222";
                dr[5] = "<a class='personPopupTrigger' rel='rel' type='place' name='" + "onebit_01.png" + "' href='#'><img src='../objects/place/onebit_01.png' width='40' height='40' /></a>";
                string wen = "                                           <table align='center'>                                                                ";
                wen += "                 <tr>                                                                                             ";
                wen += "                     <td class='none only' style='width: 60px; max-height: 60px;'>                                ";
                wen += "                         <div id='timed_p'>                                                                         ";
                wen += "                             <div style='vertical-align: bottom; min-width: 100%; max-width: 70px; height: 60px;  ";
                wen += "                                 text-align: center; font-size: 11px; line-height: 105%;'>                        ";
                wen += "                                 <div id='dtDay_p'>                                                                 ";
                wen += "                                     " + DateTime.Now.Day + "                                                                           ";
                wen += "                                 </div>                                                                           ";
                wen += "                                 <br />                                                                           ";
                wen += "                                 <div id='dtMonth_p' style='font-size: 24px; font-weight: bold; color: #CCC;'>      ";
                wen += "                                    " + DateTime.Now.Month + "                                                                           ";
                wen += "                                 </div>                                                                           ";
                wen += "                                 <br />                                                                           ";
                wen += "                                 <div id='dtYear_p'>                                                                ";
                wen += "                                     " + DateTime.Now.Year + "                                                                         ";
                wen += "                                 </div>                                                                           ";
                wen += "                             </div>                                                                               ";
                wen += "                         </div>                                                                                   ";
                wen += "                     </td>                                                                                        ";
                wen += "                 </tr>                                                                                            ";
                wen += "             </table>                                                                                             ";
                dr[6] = wen;
                dr[7] = "<a class='personPopupTrigger' rel='rel' type='activity' name='" + "Oke4 (pail).png" + "' href='#'><img src='../objects/activity/Oke4 (pail).png' width='40' height='40' /></a>";
                //string str = "<a class='personPopupTrigger' href='#'  rel='"+ dr["userid"] +"' type='"+ "people" +"' name='"+dr["userfullname"]+"'> <img src='" + dr[2] + "/></a>";

                //dr[1] = str;

                dt.Rows.Add(dr);
            }
            rptPosts.DataSource = dt;
            rptPosts.DataBind();
        }

        protected void rptPosts_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater with = ((Repeater)e.Item.FindControl("rptWith"));


                if (with != null)
                {
                    //LoginHelper helper = new LoginHelper();
                    with.DataSource = GetFiles("people");
                    //with.DataSource = helper.GetObjectsByClass("people");
                    with.DataBind();
                }

                //Literal ltWho = ((Literal)e.Item.FindControl("ltWho"));
                //Literal ltWhen = ((Literal)e.Item.FindControl("ltWhen"));

                //string str = "<a class=\"personPopupTrigger\" href=\"#\" onclick=\"javascript:return false;\" rel=\"1280\"            ";
                //str += "          type=\"type\" name=\"profile\">                                         ";
                //str += "          <img src=\"../Objects/event/test.jpg\" width=\"40\" height=\"40\" /></a>    ";
                //ltWho.Text = "awsd";
                System.Threading.Thread.Sleep(500);
                //string str2 =  "<table style=\"width:100%;\">";
                //       str2 += " <tr>        ";
                //       str2 += "     <td>    ";
                //       str2 += "     WHO     ";
                //       str2 += "     </td>   ";
                //       str2 += "     <td>    ";
                //       str2 += "     WHEN    ";
                //       str2 += "     </td>   ";
                //       str2 += "     <td>    ";
                //       str2 += "     WHERE   ";
                //       str2 += "     </td>   ";
                //       str2 += " </tr>       ";
                //       str2 += " <tr>        ";
                //str2 += "<td>
                string str2 = "<a class=\"personPopupTrigger\" href=\"#\" onclick=\"javascript:return false;\" rel=\"1288\"";
                str2 += "          type=\"type\" name=\"profile\">                                         ";
                str2 += "          <img src=\"../Objects/event/test.jpg\" width=\"40\" height=\"40\" /></a>";
                str2 += "<hr/>" + str2;
                //str2 += "</td><td></td><td></td>";
                //str2 += "</tr></table>";

                //ltWhen.Text = str2;
            }

        }

        public DataTable GetFiles(string folder)
        {
            DataTable dt2 = new DataTable();
            dt2.Columns.Add("id");
            dt2.Columns.Add("fullname");
            dt2.Columns.Add("type");
            FileInfo fi = new FileInfo(Server.MapPath("~/Objects/" + folder + "/"));
            DirectoryInfo di = fi.Directory;
            FileInfo[] fsi = di.GetFiles();
            int syc = 0;
            //Response.Write("The directory contains the following files and directories:" + di.FullName + "<hr>");
            foreach (FileSystemInfo info in fsi)
            {
                DataRow dr2 = dt2.NewRow();
                dr2[0] = info.Name;//info.Name.Split(' ')[1].TrimEnd(')').TrimStart('(');
                dr2[1] = info.Name; // info.Name.Split(' ')[0].TrimEnd('_');
                dr2[2] = folder;
                dt2.Rows.Add(dr2);
            }

            return dt2;
        }
    }
}